package com.jason.cloud.engine.share.driver.enterprise.service;

import com.jason.cloud.engine.share.driver.enterprise.bean.EnterpriseBean;
import com.jason.cloud.engine.share.driver.enterprise.dao.EnterpriseDao;
import com.jason.cloud.engine.share.driver.pack.bean.PackBean;
import com.jason.cloud.engine.share.driver.pack.dao.PackDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EnterpriseServiceImpl implements EnterpriseService {

    private static final Logger logger = LoggerFactory.getLogger(EnterpriseServiceImpl.class);

    @Resource
    private EnterpriseDao enterpriseDao;

    /**
     * 根据ID查询对象
     * @param id
     * @return
     */
    public EnterpriseBean queryEnterpriseById(String id) {
        EnterpriseBean enterpriseBean = null;
        try {
            enterpriseBean = this.enterpriseDao.queryEnterpriseById(id);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return enterpriseBean;
    }

    /**
     * 保存
     * @param enterprise
     * @return
     */
    public void insertEnterprise(EnterpriseBean enterprise) {
        try {
            this.enterpriseDao.insertEnterprise(enterprise);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 列举出所有的企业
     * @return
     */
    public List<EnterpriseBean> getEnterpriseByLimit(int page, int size) {
        List<EnterpriseBean> enterpriseBean = new ArrayList<EnterpriseBean>();
        try {
            enterpriseBean = this.enterpriseDao.getEnterpriseByLimit(page, size);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return enterpriseBean;
    }

    /**
     * 计数企业
     * @return
     */
    public int getEnterpriseCount() {
        int count = 0;
        try {
            count = this.enterpriseDao.getEnterpriseCount();
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
        return count;
    }

    /**
     * 更新企业注册信息
     * @param enterpriseBean
     */
    public void updateEnterpriseParam(EnterpriseBean enterpriseBean) {
        try {
            this.enterpriseDao.updateEnterpriseParam(enterpriseBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }

    /**
     * 更新企业资费
     * @param enterpriseBean
     */
    public void updateEnterprisePackAndEffect(EnterpriseBean enterpriseBean) {
        try {
            this.enterpriseDao.updateEnterprisePackAndEffect(enterpriseBean);
        } catch (Exception e) {
            logger.debug(e.getMessage());
        }
    }
}
